home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / vbcodwiz / vbcwur.exe / VBCWUR.ZIP / TEXTCODE.DB_ / TEXTCODE.DB
Encoding:
INI File  |  1995-05-01  |  6.2 KB  |  203 lines

  1. [1]
  2. FrameControl is used to draw frames around controls. Pass it: the name of the form, the name of the control, the offset, and the width of the frame. 5 is a good offset, 1 or 2 a good width.
  3.  
  4. [Code]
  5. 'Declares for FrameControl
  6. Global Const HiColor = &HFFFFFF
  7. Global Const LoColor = &H808080
  8.  
  9. Sub FrameControl (F As Form, C As Control, OffSet As Integer, Width As Integer)
  10. F.DrawWidth = Width
  11. F.forecolor = &HFFFFFF
  12. 'bottom:
  13. F.Line (C.Left, C.Top + C.Height + Offset)-(C.Left + C.Width, C.Top + C.Height + Offset)
  14. 'right:
  15. F.Line (C.Left + C.Width + Offset, C.Top)-(C.Left + C.Width + Offset, C.Top + C.Height + Offset)
  16. F.forecolor = &H808080
  17. 'top:
  18. F.Line (C.Left - Offset * 1.5, C.Top - Offset * 1.5)-(C.Left + C.Width + Offset * 1.5, C.Top - Offset * 1.5)
  19. 'left:
  20. F.Line (C.Left - Offset * 1.5, C.Top - Offset * 1.5)-(C.Left - Offset * 1.5, C.Top + C.Height + Offset)
  21. End Sub
  22. [Stop]
  23. [2]
  24. GetSysDir returns the path of the Windows System directory
  25.  
  26. Pass it the name of the string you want SysPath assigned to.
  27. [Code]
  28. 'Declares for GetSystemDir
  29. Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  30.  
  31. Sub GetSystemDir (SystemPath$)
  32. DIM Sys As String * 256   
  33. x = GetSystemDirectory(Sys, Len(Sys))
  34. x = InStr(1, Sys, Chr$(0))
  35. SystemPath$ = Left$(Sys, Instr(Sys,Chr$(0))-1)
  36. End Sub
  37. [Stop]
  38. [3]
  39. CenterForm centers the form passed to it horizontally and vertically on the screen. 
  40. [Code]
  41. Sub CenterForm (F As Form)
  42. F.Left = (Screen.Width - F.Width) / 2
  43. F.Top = (Screen.Height - F.Height) / 2
  44. End Sub
  45. [Stop]
  46. [4]
  47. Loaded tells if an app of the passed classname is loaded
  48. [Code]
  49. 'Declares for Loaded
  50. Declare Function FindWindow Lib "user" (ByVal CName As Any, ByVal Caption As Any)
  51.  
  52. Function Loaded (ClassName$)
  53. Loaded = FindWindow(ClassName$, 0&)
  54. End Function
  55. [Stop]
  56. [5]
  57.  
  58. [Code]
  59. Sub WaitSecs (secs)
  60. Dim sTart!, Temp%
  61.     start! = Timer
  62.     While Timer < start! + secs +1
  63.          Temp% = DoEvents()
  64.     Wend
  65. End Sub
  66. [Stop]
  67. [6]
  68. ActiveForm, ActiveControl Properties Example 2
  69.  
  70. [Code]
  71. ActiveForm, ActiveControl Properties Example 2
  72.  
  73.  
  74.  
  75. 'Declares for ActiveForm, ActiveControl Properties Example 2
  76.  
  77.  
  78. ActiveForm, ActiveControl Properties Example 2
  79.  
  80. The example shows how you can use the Clipboard in cut, copy, paste, and delete operations 
  81. using buttons on a toolbar.  To try this example, draw a text box and a check box on Form1, then 
  82. create a new MDI form.  On the MDI form, draw a picture box and then draw a command button in 
  83. the picture box.  Set the Index property on the command button to 0 (this creates a control array).  
  84. On Form1, set the MDIChild property to True.
  85. To run the example, copy the code into the Declarations section of the MDI form and press F5.  
  86. Notice that if the check box has the focus, the buttons don't work.
  87.  
  88. Sub MDIForm_Load ()
  89.     Dim I                        ' Declare variable.
  90.     Command1(0).Move 0, 0, 700, 300    ' Position button on toolbar.
  91.     For I = 1 To 3    ' Create other buttons.
  92.         Load Command1(I)    ' Create button.
  93.         Command1(I).Move I * 700, 0, 700, 300    ' Place and size button.
  94.         Command1(I).Visible = True    ' Display button.
  95.     Next I
  96.     Command1(0).Caption = "Cut"    ' Set button captions.
  97.     Command1(1).Caption = "Copy"
  98.     Command1(2).Caption = "Paste"
  99.     Command1(3).Caption = "Del"
  100. End Sub
  101.  
  102. Sub Command1_Click (Index As Integer)
  103.     ' ActiveForm refers to the active form in the MDI form.
  104.     If TypeOf ActiveForm.ActiveControl Is TextBox Then
  105.         Select Case Index
  106.             Case 0            ' Cut.
  107.                 ' Copy selected text to Clipboard.
  108.                 Clipboard.SetText ActiveForm.ActiveControl.SelText
  109.                 ' Delete selected text.
  110.                 ActiveForm.ActiveControl.SelText = ""
  111.             Case 1            ' Copy.
  112.                 ' Copy selected text to Clipboard.
  113.                 Clipboard.SetText ActiveForm.ActiveControl.SelText
  114.             Case 2            ' Paste.
  115.                 ' Put Clipboard text in text box.
  116.                 ActiveForm.ActiveControl.SelText = Clipboard.GetText()
  117.             Case 3            ' Delete.
  118.                 ' Delete selected text.
  119.                 ActiveForm.ActiveControl.SelText = ""
  120.         End Select
  121.     End If
  122. End Sub
  123.  
  124.  
  125. [Stop]
  126. [7]
  127. AutoRedraw Property Example
  128. [Code]
  129. AutoRedraw Property Example
  130.  
  131.  
  132. 'Declares for AutoRedraw Property Example
  133.  
  134. AutoRedraw Property Example
  135.  
  136. The example alternately displays two drawings on a picture box control: a persistent filled circle 
  137. and temporary vertical lines.  Click the picture box to draw or redraw the lines.  Resizing the form 
  138. requires the temporary drawing to be redrawn.  To try this example, paste the code into the 
  139. Declarations section of a form that has a picture box control named Picture1.  Press F5 to run the 
  140. program and click the picture each time you resize the form.
  141.  
  142. Sub Form_Load ()
  143.     Picture1.ScaleHeight = 100    ' Set scale to 100.
  144.     Picture1.ScaleWidth = 100
  145.     Picture1.AutoRedraw = True    ' Turn on AutoRedraw.
  146.     Picture1.ForeColor = 0    ' Set ForeColor.
  147.     Picture1.FillColor = QBColor(9)    ' Set FillColor.
  148.     Picture1.FillStyle = 0    ' Set FillStyle.
  149.     Picture1.Circle (50, 50), 30    ' Draw a circle.
  150.     Picture1.AutoRedraw = False    ' Turn off AutoRedraw.
  151. End Sub
  152.  
  153.  
  154. Sub Picture1_Click ()
  155.     Dim I            ' Declare variable.
  156.     Picture1.ForeColor = Rgb(Rnd * 255, 0, 0)    ' Select random color.
  157.     For I = 5 To 95 Step 10    ' Draw lines.
  158.         Picture1.Line (I, 0)-(I, 100)
  159.     Next
  160. End Sub
  161.  
  162.  
  163. [Stop]
  164. [8]
  165. BOF, EOF Properties Example
  166. [Code]
  167. BOF, EOF Properties Example
  168.  
  169.  
  170. 'Declares for BOF, EOF Properties Example
  171.  
  172. BOF, EOF Properties Example
  173.  
  174. This example uses the BOF and EOF properties to detect the limits of the Publishers table.  It 
  175. moves through the records first from the beginning of the file to the end, and then from the end to the 
  176. beginning.  The MoveLast method is required because there is no current record immediately 
  177. following the first loop.
  178.  
  179. Data1.DatabaseName = "BIBLIO.MDB"
  180. Data1.RecordSource = "Publishers"    ' Open table.
  181. ...
  182. Do Until Data1.Recordset.EOF    ' Until end of file.
  183.     ...
  184.     Data1.Recordset.MoveNext    ' Move to next record.
  185. Loop
  186. Data1.Recordset.MoveLast    ' Move to last record.
  187. Do Until Data1.Recordset.BOF    ' Until beginning of file.
  188.     ...
  189.     Data1.Recordset.MovePrevious    ' Move to previous record.
  190. Loop
  191.  
  192.  
  193. [Stop]
  194. [9]
  195. MYNEWTEST
  196. [Code]
  197. MYNEWTEST
  198.  
  199.  
  200. 'Declares for MYNEWTEST
  201. THIS IS MY NEW TEST OF THE VBMANAGER PROGRAM
  202. [Stop]
  203.